<?php

use Illuminate\Database\Seeder;

class PostTagTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        //

        $faker = Faker\Factory::create();
        $post_ids = \App\Models\Post::pluck('id')->toArray();
        $tag_ids = \App\Models\Tag::pluck('id')->toArray();
        $datas = [];
        foreach (range(1, 20) as $key => $value) {
            $datas[] = [
                'post_id' =>  $faker->randomElement($post_ids) ,
                'tag_id' =>  $faker->randomElement($tag_ids) ,
                'created_at' => \Carbon\Carbon::now()->toDateTimeString(),
                'updated_at' => \Carbon\Carbon::now()->toDateTimeString()
            ];
        }
        DB::table('post_tag')->insert($datas);
    }
}
